<template>
    <div class="app-container"
         v-loading.fullscreen.lock="allLoading"
         element-loading-text="拼命处理中,请耐心等待"
         element-loading-spinner="el-icon-loading"
         element-loading-background="rgba(0, 0, 0, 0.8)"
    >
        <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="showDialog" width="1500px"  append-to-body @close="closeDialog">
            <el-form ref="form" :model="form" :rules="rules" label-width="120px">
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="表名" prop="tableName">
                            <el-input  v-model="form.tableName"  clearable  >
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="应用名" prop="appName">
                            <el-input  v-model="form.appName"  clearable  >
                            </el-input>
                        </el-form-item>
                        <el-form-item label="应用类型" prop="appType">
                            <el-radio-group v-model="form.appType" size="medium">
                                <el-radio v-for="(item, index) in appTypeOptions" :key="index" :label="item.value"
                                          :disabled="item.disabled">{{item.label}}</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <el-row>
            </el-row>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitMainDialog">确 定</el-button>
                <el-button @click="cancelMainDialog">取 消</el-button>
            </div>
        </el-dialog>

    </div>
</template>

<script>
import { autumnFormMixin } from '../../../components/autumn/autumn-form'
import { addAutumnApp, updateAutumnApp } from '../../../api/tool/autumnApp'
import { appTypeOptions } from './indexScript'
export default {
    name: 'AutumnAppAddFormDialog',
    components: {
    },
    mixins: [autumnFormMixin],
    data:()=>{
        return {
            lookupCompanyDialog:{
                // title: '选择',
                showDialog: false,
                queryParams: {

                },
            },

            defaultForm:{
                virtualCompany: {},
                companyId: undefined,
            },

            rules:{
                tableName:[
                    { required: true, message: "不能为空", trigger: "change" }
                ],
                appName: [
                    { required: true, message: "不能为空", trigger: "change" }
                ],
                appType: [{ required: true, message: '不能为空', trigger: 'change' }],
            },

            appTypeOptions: appTypeOptions,

        }
    },
    methods:{
        submitMainDialog(){
            this.$refs.form.validate(valid => {
                if (!valid) {
                    return
                }
                switch(this.form.virtualChangeBitFlag){
                    case this.CHANGE_BIT_FLAG.add:
                        this.allLoading = true;
                        addAutumnApp(this.form).then(response => {
                            this.msgSuccess();
                            this.showDialog = false;
                            this.allLoading=false;
                        }).catch(error => {
                            this.allLoading=false;
                        });
                        break;
                    case this.CHANGE_BIT_FLAG.modify:
                        this.allLoading = true;
                        updateAutumnApp(this.form).then(response => {
                            this.msgSuccess();
                            this.showDialog = false;
                            this.allLoading=false;
                        }).catch(error => {
                            this.allLoading=false;
                        });
                            break;
                    default:
                        break;
                }
            })
        },
        cancelMainDialog(){
            this.showDialog=false
        },
        closeDialog(){
            this.$emit('close')
        },

        showLookupCompany(uid){
            //console.log("showLookupDomain.")
            this.lookupCompanyDialog.queryParams={
                typeAndTrue: 1
                //默认筛选
            }
            //有默认查询条件时初始化弹出框查询列表
            this.lookupCompanyDialog.uid=uid;
            this.lookupCompanyDialog.showDialog=true;
        },

        //添加按钮点击后,不同按钮调用根据调用时设置的uid判断
        handleAddButtonLookupCompany(row,uid){

            this.lookupCompanyDialog.showDialog=false;
            //console.log("handleAddButtonLookupCompany.row=",row,"uid",uid);
            if(uid=='form.companyId'){
                this.form.companyId=row.companyId;
                this.form.virtualCompany=row;

                this.createPurchaseOrderBomTable.queryParams={
                    companyId: row.companyId,
                    workStatusAndTrue: 0,
                    workStatusAndFalse: 1,
                }
                console.log("this.createPurchaseOrderBomTable.queryParams",this.createPurchaseOrderBomTable.queryParams)
                return ;
            }
            if(uid=='queryParams.companyId'){
                this.queryParams.companyId=row.companyId
                this.queryParams.virtualCompanyIdLabel=row.companyName;
                this.$forceUpdate();
                return ;
            }
        },
    },
}
</script>

<style scoped>

</style>
